import {
    Column,
    CreateDateColumn,
    Entity,
    JoinTable,
    ManyToMany,
    PrimaryGeneratedColumn,
    UpdateDateColumn,
  } from 'typeorm';
  import { Permission } from './permission.entity';
  import { Users } from './users.entity';
  
  @Entity()
  export class Role {
    @PrimaryGeneratedColumn()
    id: number;
  
    @Column({
      length: 20,
    })
    name: string;

    @Column({
        length: 100,
        nullable: true
    })
    desc: string;
  
    @CreateDateColumn({
        type: 'timestamp',
        comment: '创建时间',
        default: null,
        name: 'create_time'
    })
    createTime: Date;
  
    @UpdateDateColumn({
        type: 'timestamp',
        comment: '更新时间',
        default: null,
        name: 'update_time'
    })
    updateTime: Date;
  
    @ManyToMany(() => Permission)
    @JoinTable({
      name: 'role_permission_relation',
    })
    permissions: Permission[];

    @ManyToMany(
        () => Users,
        user => user.roles
    )
    users: Array<Users>;
  }